home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 September / CHIP Eylül 1998.iso / Slackwar / docs / Tips-HOWTO < prev    next >
Text File  |  1998-01-05  |  29KB  |  735 lines

  1.   The Linux Tips HOWTO
  2.   Paul Anderson, paul@geeky1.ebtech.net
  3.   v3.1, 26 December 1997
  4.  
  5.   This HOWTO contains those hard to find hints and tweekings that make
  6.   Linux a bit nicer.
  7.  
  8.   1.  Introduction
  9.  
  10.   Welcome to the Linux Tips HOWTO, a list of neato tricks and
  11.   optimizations that make Linux more fun.  All I have in here right now
  12.   are tips off of the top of my head, and tips from the old Tips-
  13.   HOWTO(Why take out decent tips, right?).  So send all your favorite
  14.   hints and tips to me so I can put them in the next Tips-HOWTO.
  15.  
  16.   Paul Anderson Maintainer--Linux TIPS HOWTO
  17.  
  18.   panderso@ebtech.net
  19.  
  20.   2.  Short Tips
  21.  
  22.   2.1.  Handy Syslog Trick Paul Anderson, Tips-HOWTO maintainer
  23.  
  24.   Edit your /etc/syslog.conf, and put in the following line:
  25.  
  26.        # Dump everything on tty8
  27.        *.*                                     /dev/tty8
  28.  
  29.   One caveat: REMEMBER TO USE TABS!  syslog doesn't like spaces...
  30.  
  31.   2.2.  Script to view those compressed HOWTOs. Didier Juges,
  32.   dj@destin.nfds.net
  33.  
  34.   From a newbie to another, here is a short script that eases looking
  35.   for and viewing howto documents.  My howto's are in
  36.   /usr/doc/faq/howto/ and are gzipped. The file names are XXX-HOWTO.gz,
  37.   XXX being the subject.  I created the following script called "howto"
  38.   in the /usr/local/sbin directory:
  39.  
  40.        ______________________________________________________________________
  41.        #!/bin/sh
  42.        if [ "$1" = "" ]; then
  43.            ls /usr/doc/faq/howto | less
  44.        else
  45.            gunzip -c /usr/doc/faq/howto/$1-HOWTO.gz | less
  46.        fi
  47.        ______________________________________________________________________
  48.  
  49.   When called without argument, it displays a directory of the available
  50.   howto's. Then when entered with the first part of the file name
  51.   (before the hyphen) as an argument, it unzips (keeping the original
  52.   intact) then displays the document.
  53.  
  54.   For instance, to view the Serial-HOWTO.gz document, enter:
  55.  
  56.   $ howto Serial
  57.  
  58.   2.3.  Is there enough free space??? Hans Zoebelein,
  59.   zocki@goldfish.cube.net
  60.  
  61.   Here comes a short script which will check from time to time that
  62.   there is enough free space available on anything which shows up in
  63.   mount (disks, cdrom, floppy...)
  64.  
  65.   If space runs out, a message is printed every X seconds to the screen
  66.   and 1 mail message per filled device is fired up.
  67.  
  68.   ______________________________________________________________________
  69.   #!/bin/sh
  70.  
  71.   #
  72.   # $Id: check_hdspace,v 1.18 1996/12/11 22:33:29 root Exp root $
  73.   #
  74.  
  75.   #
  76.   # Since I got mysterious error messages during compile when
  77.   # tmp files filled up my disks, I wrote this to get a warning
  78.   # before disks are full.
  79.   #
  80.   # If this stuff saved your servers from exploding,
  81.   # send praising email to zocki@goldfish.cube.net.
  82.   # If your site burns down because of this, sorry but I
  83.   # warned you: no comps.
  84.   # If you really know how to handle sed, please forgive me :)
  85.   #
  86.  
  87.   #
  88.   # Shoot and forget: Put 'check_hdspace &' in rc.local.
  89.   # Checks for free space on devices every $SLEEPTIME sec.
  90.   # You even might check your floppies or tape drives. :)
  91.   # If free space is below $MINFREE (kb), it will echo a warning
  92.   # and send one mail for each triggering device to $MAIL_TO_ME.
  93.   # If there is more free space than trigger limit again,
  94.   # mail action is also armed again.
  95.   #
  96.  
  97.   # TODO: Different $MINFREE for each device.
  98.   # Free /*tmp dirs securely from old junk stuff if no more free space.
  99.  
  100.   DEVICES='/dev/sda2 /dev/sda8 /dev/sda9'         # device; your put disks here
  101.   MINFREE=20480                                   # kb; below this do warning
  102.   SLEEPTIME=10                                    # sec; sleep between checks
  103.   MAIL_TO_ME='root@localhost'                     # fool; to whom mail warning
  104.  
  105.   # ------- no changes needed below this line (hopefully :) -------
  106.  
  107.   MINMB=0
  108.   ISFREE=0
  109.   MAILED=""
  110.   let MINMB=$MINFREE/1024         # yep, we are strict :)
  111.  
  112.   while [ 1 ]; do
  113.           DF="`/bin/df`"
  114.                   for DEVICE in $DEVICES ; do
  115.                   ISFREE=`echo $DF | sed s#.\*$DEVICE" "\*[0-9]\*""\*[0-9]\*" "\*## | sed s#" ".\*##`
  116.  
  117.                   if [ $ISFREE -le $MINFREE ] ; then
  118.                           let ISMB=$ISFREE/1024
  119.                           echo  "WARNING: $DEVICE only $ISMB mb free." >&2
  120.                           #echo "more stuff here" >&2
  121.                           echo -e "\a\a\a\a"
  122.  
  123.                           if [ -z  "`echo $MAILED | grep -w $DEVICE`" ] ; then
  124.                                   echo "WARNING: $DEVICE only $ISMB mb free.      (Trigger is set to $MINMB mb)" \
  125.                                   | mail -s "WARNING: $DEVICE only $ISMB mb free!" $MAIL_TO_ME
  126.                                   MAILEDH="$MAILED $DEVICE"
  127.                                   MAILED=$MAILEDH
  128.                                   # put further action here like cleaning
  129.                                   # up */tmp dirs...
  130.                           fi
  131.                           elif [ -n  "`echo $MAILED | grep -w $DEVICE`" ] ; then
  132.                                   # Remove mailed marker if enough disk space
  133.                                   # again. So we are ready for new mailing action.
  134.                                   MAILEDH="`echo $MAILED  | sed s#$DEVICE##`"
  135.                                   MAILED=$MAILEDH
  136.                           fi
  137.  
  138.                   done
  139.                   sleep $SLEEPTIME
  140.  
  141.   done
  142.   ______________________________________________________________________
  143.  
  144.   2.4.  Util to clean up your logfiles. Paul Anderson, Tips-HOWTO Main¡
  145.   tainer>
  146.  
  147.   If you're like me, you have a list with 250 subscribers, plus 100+
  148.   messages per day coming in over UUCP.  Well, what's a hacker to do
  149.   with these huge logs?  Install chklogs, that's what.  Chklogs is
  150.   written by Emilio Grimaldo, grimaldo@panama.iaehv.nl, and the current
  151.   version 1.8 available from
  152.   ftp.iaehv.nl:/pub/users/grimaldo/chklogs-1.8.tar.gz.  It's pretty self
  153.   explanatory to install(you will, of course, check out the info in the
  154.   doc subdirectory).  Once you've got it installed, add a crontab entry
  155.   like this:
  156.  
  157.        # Run chklogs at 9:00PM daily.
  158.        00 21 * * *       /usr/local/sbin/chklogs -m
  159.  
  160.   While you're at it, mention to the author how nice a peice of software
  161.   this is:)
  162.  
  163.   2.5.  ohammers@cu-online.com Handy Script to Clean Up Corefiles. Otto
  164.   Hammersmith,
  165.  
  166.   Create a file called rmcores(the author calls it handle-cores) with
  167.   the following in it:
  168.  
  169.   ______________________________________________________________________
  170.   #!/bin/sh
  171.   USAGE="$0 <directory> <message-file>"
  172.  
  173.   if [ $# != 2 ] ; then
  174.           echo $USAGE
  175.           exit
  176.   fi
  177.  
  178.    echo Deleting...
  179.   find $1 -name core -atime 7 -print -exec rm {} \;
  180.  
  181.   echo e-mailing
  182.   for name in `find $1 -name core -exec ls -l {} \; | cut -c16-24`
  183.   do
  184.           echo $name
  185.           cat $2 | mail $name
  186.   done
  187.   ______________________________________________________________________
  188.  
  189.   And have a cron job run it every so often.
  190.  
  191.   2.6.  Moving directories between filesystems. Alan Cox,
  192.   A.Cox@swansea.ac.uk
  193.  
  194.   Quick way to move an entire tree of files from one disk to another
  195.  
  196.        (cd /source/directory && tar cf - . ) | (cd /dest/directory && tar xvfp -)
  197.  
  198.    Change from cd /source/directory; tar....etc.  to prevent possibility
  199.   of trashing directory in case of disaster.  Thanks to Jim Dennis,
  200.   jadestar@rahul.net, for letting me know. -Maint.
  201.  
  202.   2.7.  mghazey@miso.lowdown.com Finding out which directories are the
  203.   largest. Mick Ghazey,
  204.  
  205.   Ever wondered which directories are the biggest on your computer?
  206.   Here's how to find out.
  207.  
  208.        du -S | sort -n
  209.  
  210.   2.8.  The Linux Gazette
  211.  
  212.   Kudos go to John Fisk, creator of the Linux Gazette.  This is an
  213.   excellent e-zine plus, it's FREE!!!  Now what more could you ask?
  214.   Check it out at:
  215.  
  216.        http://www.ssc.com/lg
  217.  
  218.   BTW, It turns out that (1) LG is now out on a monthly basis, and (2)
  219.   John Fisk no longer maintains it, the fellows at SSC do.
  220.  
  221.   2.9.  Ted Stern, stern@amath.washington.edu Pointer to patch for GNU
  222.   Make 3.70 to change VPATH behavior.
  223.  
  224.   I don't know if many people have this problem, but there is a
  225.   "feature" of GNU make version 3.70 that I don't like. It is that VPATH
  226.   acts funny if you give it an absolute pathname.  There is an extremely
  227.   solid patch that fixes this, which you can get from Paul D. Smith
  228.   <psmith@wellfleet.com>.  He also posts the documentation and patch
  229.   after every revision of GNU make on the newsgroup system I have access
  230.   to.
  231.  
  232.   2.10.  How do I stop my system from fscking on each reboot? Dale Lutz,
  233.   dal@wimsey.com
  234.  
  235.   Q:  How do I stop e2fsck from checking my disk every time I boot up.
  236.  
  237.   A:  When you rebuild the kernel, the filesystem is marked as 'dirty'
  238.   and so your disk will be checked with each boot.  The fix is to run:
  239.  
  240.   rdev -R /zImage 1
  241.  
  242.   This fixes the kernel so that it is no longer convinced that the
  243.   filesystem is dirty.
  244.  
  245.   Note: If using lilo, then add read-only to your linux setup in your
  246.   lilo config file (Usually /etc/lilo.conf)
  247.  
  248.   2.11.  How to avoid fscks caused by "device busy" at reboot time. Jon
  249.   Tombs, jon@gtex02.us.es
  250.  
  251.   If you often get device busy errors on shutdown that leave the
  252.   filesystem in need of an fsck upon reboot, here is a simple fix:
  253.  
  254.   To /etc/rc.d/init.d/halt or /etc/rc.d/rc.0, add the line
  255.  
  256.        mount -o remount,ro /mount.dir
  257.  
  258.   for all your mounted filesystems except /, before the call to umount
  259.   -a. This means if, for some reason, shutdown fails to kill all pro¡
  260.   cesses and umount the disks they will still be clean on reboot. Saves
  261.   a lot of time at reboot for me.
  262.  
  263.   2.12.  How to find the biggest files on your hard-drive.
  264.  
  265.   Simon Amor, simon@foobar.co.uk
  266.  
  267.        ls -l | sort +4n
  268.  
  269.   Or, for those of you really scrunched for space this takes awhile but
  270.   works great:
  271.  
  272.        cd /
  273.        ls -lR | sort +4n
  274.  
  275.   2.13.  How to print pages with a margin for hole punching. Mike
  276.   Dickey, mdickey@thorplus.lib.purdue.edu
  277.  
  278.        ______________________________________________________________________
  279.                #!/bin/sh
  280.                # /usr/local/bin/print
  281.                # a simple formatted printout, to enable someone to
  282.                # 3-hole punch the output and put it in a binder
  283.  
  284.                cat $1 | pr -t -o 5 -w 85 | lpr
  285.        ______________________________________________________________________
  286.  
  287.   2.14.  Raul Deluth Miller, rockwell@nova.umd.edu A way to search
  288.   through trees of files for a particular regular expression.
  289.  
  290.   I call this script 'forall'.  Use it like this:
  291.  
  292.        forall /usr/include grep -i ioctl
  293.        forall /usr/man grep ioctl
  294.  
  295.   Here's forall:
  296.  
  297.        ______________________________________________________________________
  298.        #!/bin/sh
  299.        if [ 1 = `expr 2 \> $#` ]
  300.        then
  301.                echo Usage: $0 dir cmd [optargs]
  302.                exit 1
  303.        fi
  304.        dir=$1
  305.        shift
  306.        find $dir -type f -print | xargs "$@"
  307.        ______________________________________________________________________
  308.  
  309.   2.15.  Barry Tolnas, tolnas@nestor.engr.utk.edu A script for cleaning
  310.   up after programs that create autosave and backup files.
  311.  
  312.   Here is a simple two-liner which recursively descends a directory
  313.   hierarchy removing emacs auto-save (#) and backup (~) files, .o files,
  314.   and  TeX .log files. It also compresses .tex files and README files. I
  315.   call it 'squeeze' on my system.
  316.  
  317.        ______________________________________________________________________
  318.        #!/bin/sh
  319.        #SQUEEZE removes unnecessary files and compresses .tex and README files
  320.        #By Barry tolnas, tolnas@sun1.engr.utk.edu
  321.        #
  322.        echo squeezing $PWD
  323.        find  $PWD \( -name \*~ -or -name \*.o -or -name \*.log -or -name \*\#\) -exec
  324.        rm -f {} \;
  325.        find $PWD \( -name \*.tex -or -name \*README\* -or -name \*readme\* \) -exec gzip -9 {} \;
  326.        ______________________________________________________________________
  327.  
  328.   2.16.  simon@foobar.co.uk How to find out what process is eating the
  329.   most memory. Simon Amor,
  330.  
  331.        ps -aux | sort +4n
  332.  
  333.   -OR-
  334.  
  335.        ps -aux | sort +5n
  336.  
  337.   2.17.  Rigging vi for C programming, Paul Anderson,Tips-HOWTO Main¡
  338.   tainer
  339.  
  340.   I do a lot of C programming in my spare time, and I've taken the time
  341.   to rig vi to be C friendly.  Here's my .exrc:
  342.  
  343.        ______________________________________________________________________
  344.        set autoindent
  345.        set shiftwidth=4
  346.        set backspace=2
  347.        set ruler
  348.        ______________________________________________________________________
  349.  
  350.   What does this do?  autoindent causes vi to automatically indent each
  351.   line following the first one indented, shiftwidth sets the distance of
  352.   ^T to 4 spaces, backspace sets the backspace mode, and ruler makes it
  353.   display the line number.  Remember, to go to a specific line number,
  354.   say 20, use:
  355.  
  356.   ______________________________________________________________________
  357.   vi +20 myfile.c
  358.   ______________________________________________________________________
  359.  
  360.   2.18.  paul@geeky1.ebtech.net Why does sendmail hang for 5 minutes on
  361.   startup with RedHat? Paul Anderson,
  362.  
  363.   This is a fairly common problem, almost to the point of being a FAQ.
  364.   I don't know if RedHat has fixed this bug in their distribution, but
  365.   you can repair it yourself.  If you look in your /etc/hosts file, you
  366.   will find it looks something like:
  367.  
  368.        127.0.0.1               localhost       yourbox
  369.  
  370.   When sendmail starts, it does a lookup on your hostname(in this
  371.   example, yourbox).  It then finds that the IP for yourbox is
  372.   127.0.0.1, sendmail doesn't like this, so it does the lookup again.
  373.   It continues with this for a while until it eventually gives up and
  374.   exits.  Fixing the problem is extremely easy, edit your /etc/hosts
  375.   file and change it to something like this:
  376.  
  377.        127.0.0.1               localhost
  378.        10.56.142.1             yourbox
  379.  
  380.   2.19.  How do I configure RedHat for using color-ls? Paul Anderson,
  381.   paul@geeky1.ebtech.net
  382.  
  383.   RedHat's distribution comes with color-ls, however why they don't
  384.   configure it for colour use by default is beyond me.  Here's to fix
  385.   it.
  386.  
  387.   First, type eval `DIRCOLORS`
  388.  
  389.   Next, alias ls='ls --color=yes'
  390.  
  391.   And put the 'alias.....' in your /etc/bashrc
  392.  
  393.   2.20.  vps@unicorn.niimm.spb.su How do I find which library in
  394.   /usr/lib holds a certain function? Pawel Veselow,
  395.  
  396.   What if you're compiling and you've missed a library that needed
  397.   linking in?  All gcc reports are function names...  Here's a simple
  398.   command that'll find what you're looking for:
  399.  
  400.        for i in *; do echo $i:;nm $i|grep tgetnum 2>/dev/null;done
  401.  
  402.   Where tgetnum is the name of the function you're looking for.
  403.  
  404.   3.  Detailed Tips
  405.  
  406.   3.1.  Sharing swap partitions between Linux and Windows. Tony Acero,
  407.   ace3@midway.uchicago.edu
  408.  
  409.   1. Format the partition as a dos partition, and create the Windows
  410.      swap file on it, but don't run windows yet. (You want to keep the
  411.      swap file completely empty for now, so that it compresses well).
  412.  
  413.   2. Boot linux and save the partition into a file.  For example if the
  414.      partition was /dev/hda8:
  415.  
  416.        dd if=/dev/hda8 of=/etc/dosswap
  417.  
  418.   3. Compress the dosswap file; since it is virtually all 0's it will
  419.      compress very well
  420.  
  421.        gzip -9 /etc/dosswap
  422.  
  423.   4. Add the following to the /etc/rc file to prepare and install the
  424.      swap space under Linux:
  425.  
  426.      XXXXX is the number of blocks in the swap partition
  427.  
  428.        mkswap /dev/hda8 XXXXX
  429.        swapon -av
  430.  
  431.   Make sure you add an entry for the swap partition in your /etc/fstab
  432.   file
  433.  
  434.   5. If your init/reboot package supports /etc/brc or /sbin/brc add the
  435.      following to /etc/brc, else do this by hand when you want to boot
  436.      to dos|os/2 and you want to convert the swap partition back to the
  437.      dos/windows version:
  438.  
  439.        swapoff -av
  440.        zcat /etc/dosswap.gz | dd of=/dev/hda8 bs=1k count=100
  441.  
  442.   # Note that this only writes the first 100 blocks back to the parti¡
  443.   tion. I've found empirically that this is sufficient
  444.  
  445.   >>  What are the pros and cons of doing this?
  446.  
  447.   Pros: you save a substantial amount of disk space.
  448.  
  449.   Cons: if step 5 is not automatic, you have to remember to do it by
  450.   hand, and it slows the reboot process by a nanosecond :-)
  451.  
  452.   3.2.  Desperate Undelete. Michael Hamilton, michael@actrix.gen.nz
  453.  
  454.   Here's a trick I've had to use a few times.
  455.  
  456.   Desperate person's text file undelete.
  457.  
  458.   If you accidentally remove a text file, for example, some email, or
  459.   the results of a late night programming session, all may not be lost.
  460.   If the file ever made it to disk, ie it was around for more than 30
  461.   seconds, its contents may still be in the disk partition.
  462.  
  463.   You can use the grep command to search the raw disk partition for the
  464.   contents of file.
  465.  
  466.   For example, recently, I accidentally deleted a piece of email.  So I
  467.   immediately ceased any activity that could modify that partition: in
  468.   this case I just refrained from saving any files or doing any compiles
  469.   etc.  On other occasions, I've actually gone to the trouble of bring
  470.   the system down to single user mode, and unmounted the filesystem.
  471.  
  472.   I then used the egrep command on the disk partition:  in my case the
  473.   email message was in /usr/local/home/michael/, so from the output from
  474.   df, I could see this was in /dev/hdb5
  475.  
  476.          sputnik3:~ % df
  477.            Filesystem         1024-blocks  Used Available Capacity Mounted on
  478.            /dev/hda3              18621    9759     7901     55%   /
  479.            /dev/hdb3             308852  258443    34458     88%   /usr
  480.            /dev/hdb5             466896  407062    35720     92%   /usr/local
  481.  
  482.            sputnik3:~ % su
  483.            Password:
  484.            [michael@sputnik3 michael]# egrep -50 'ftp.+COL' /dev/hdb5 > /tmp/x
  485.  
  486.   Now I'm ultra careful when fooling around with disk partitions, so I
  487.   paused to make sure I understood the command syntax BEFORE pressing
  488.   return.  In this case the email contained the word 'ftp' followed by
  489.   some text followed by the word 'COL'.  The message was about 20 lines
  490.   long, so I used -50 to get all the lines around the phrase.  In the
  491.   past I've used -3000 to make sure I got all the lines of some source
  492.   code.  I directed the output from the egrep to a different disk parti¡
  493.   tion - this prevented it from over writing the message I was looking
  494.   for.
  495.  
  496.   I then used strings to help me inspect the output
  497.  
  498.           strings /tmp/x | less
  499.  
  500.   Sure enough the email was in there.
  501.  
  502.   This method can't be relied on, all, or some, of the disk space may
  503.   have already been re-used.
  504.  
  505.   This trick is probably only useful on single user systems.  On multi-
  506.   users systems with high disk activity, the space you free'ed up may
  507.   have already been reused.  And most of use can't just rip the box out
  508.   from under our users when ever we need to recover a file.
  509.  
  510.   On my home system this trick has come in handy on about three
  511.   occasions in the past few years - usually when I accidentally trash
  512.   some of the days work.  If what I'm working survives to a point where
  513.   I feel I made significant progress, it get's backed up onto floppy, so
  514.   I haven't needed this trick very often.
  515.  
  516.   3.3.  How to use the immutable flag. Jim Dennis, jadestar@rahul.net
  517.  
  518.   Use the Immutable Flag
  519.  
  520.   Right after you install and configure your system go through the /bin,
  521.   /sbin/, /usr/bin, /usr/sbin and /usr/lib (and a few of the other usual
  522.   suspects and make liberal use of the 'chattr +i command'.  Also add
  523.   that to the the kernel files in root.  Now 'mkdir /etc/.dist/' copy
  524.   everything from /etc/ on down (I do this in two steps using
  525.   /tmp/etcdist.tar to avoid recursion) into that directory.  (Optionally
  526.   you can just create /etc/.dist.tar.gz) -- and mark that as immutable.
  527.  
  528.   The reason for all of this is to limit the damage that you can do when
  529.   logged in as root.  You won't overwrite files with a stray redirection
  530.   operator, and you won't make the system unusable with a stray space in
  531.   an 'rm -fr' command (you might still do alot of damage to your data --
  532.   but your libs and bins will be safer.
  533.  
  534.   This also makes a variety of security and denial of service exploits
  535.   either impossible or more difficult (since many of them rely on
  536.   overwriting a file through the actions of some SUID program that
  537.   *isn't providing an arbitrary shell command*).
  538.  
  539.   The only inconvenience of this is when building and doing your 'make
  540.   install' on various sorts of system binaries.  On the other hand it
  541.   also prevents the 'make install' from over-writing the files.  When
  542.   you forget to read the Makefile and chattr -i the files that are to be
  543.   overwritten (and the directories to which you want to add files) --
  544.   the make fails, you just use the chattr command and rerun it.  You can
  545.   also take that opportunity to move your old bin's, libs, or whatever
  546.   into a .old/ directory or rename or tar them or whatever.
  547.  
  548.   3.4.  Jim Dennis, jadestar@rahul.net A suggestion for where to put new
  549.   stuff.
  550.  
  551.   All new stuff starts under /usr/local! or /usr/local/`hostname`
  552.  
  553.   If your distribution is one that leaves /usr/local empty then just
  554.   create your /usr/local/src, /usr/local/bin etc and use that.  If your
  555.   distribution puts things in the /usr/local tree than you may want to
  556.   'mkdir /usr/local/`hostname`' and give the 'wheel' group +w to it (I
  557.   also make it SUID and SGID to insure that each member of the wheel
  558.   group can only mess with their own files thereunder, and that all
  559.   files created will belong to the 'wheel' group.
  560.  
  561.   Now discipline yourself to *ALWAYS! ALWAYS! ALWAYS!* put new packages
  562.   under /usr/local/src/.from/$WHEREVER_I_GOT_IT/ (for the .tar or
  563.   whatever files) and build them  under /usr/local/src (or
  564.   .../$HOSTNAME/src).  Make sure that it installs under the local
  565.   hierarchy.  If it *absolutely must* be installed back in /bin or
  566.   /usr/bin or somewhere else -- put a symlink from the local heirarchy
  567.   to each element that when anywhere else.
  568.  
  569.   The reason for this -- even though it's more work -- is that it helps
  570.   isolate what has to be backed up and restored or reinstalled in the
  571.   event of a full re-install from the distribution medio (usually CD
  572.   these days).  By using a /usr/local/.from directory you also keep an
  573.   informal log of where your sources are coming from -- which helps when
  574.   you're looking for new updates -- and may be critical when monitoring
  575.   the security announcement lists.
  576.  
  577.   One of my systems at home (the one I'm calling from) was put together
  578.   before I adopted these policies for myself.  I still don't "know" all
  579.   the ways that it differs from the stock "as installed" system.  This
  580.   is despite the fact that I've done very little with my home system's
  581.   configuration and I'm the *only* person who ever uses it.
  582.  
  583.   By contrast the systems I've set up at work (when I was thrust into
  584.   the role of system administrator there) have all been configured this
  585.   way -- have been administered by many contractors and other MIS
  586.   people, and have had a large number of upgrades and package
  587.   installations.  Nonetheless I have a very good idea which precise
  588.   elements were put in *after* the initial installation and
  589.   configuration.
  590.  
  591.   3.5.  Converting all files in a directory to lowercase. Justin Dossey,
  592.   dossey@ou.edu
  593.  
  594.   I noticed a few overly difficult or unnecessary procedures recommended
  595.   in the 2c tips section of Issue 12.  Since there is more than one, I'm
  596.   sending it to you:
  597.  
  598.        ______________________________________________________________________
  599.        #!/bin/sh
  600.                 # lowerit
  601.                 # convert all file names in the current directory to lower case
  602.                 # only operates on plain files--does not change the name of directories
  603.                 # will ask for verification before overwriting an existing file
  604.                 for x in `ls`
  605.                   do
  606.                   if [ ! -f $x ]; then
  607.                     continue
  608.                     fi
  609.                   lc=`echo $x  | tr '[A-Z]' '[a-z]'`
  610.                   if [ $lc != $x ]; then
  611.                     mv -i $x $lc
  612.                   fi
  613.                   done
  614.        ______________________________________________________________________
  615.  
  616.   Wow.  That's a long script.  I wouldn't write a script to do that;
  617.   instead, I would use this command:
  618.  
  619.        for i in * ; do [ -f $i ] && mv -i $i `echo $i | tr '[A-Z]' '[a-z]'`;
  620.        done;
  621.  
  622.   on the command line.
  623.  
  624.   The contributor says he wrote the script how he did for
  625.   understandability (see below).
  626.  
  627.   On the next tip, this one about adding and removing users, Geoff is
  628.   doing fine until that last step.  Reboot?  Boy, I hope he doesn't
  629.   reboot every time he removes a user.  All you have to do is the first
  630.   two steps.  What sort of processes would that user have going, anyway?
  631.   An irc bot?  Killing the processes with a simple
  632.  
  633.        kill -9 `ps -aux |grep ^<username> |tr -s " " |cut -d " " -f2`
  634.  
  635.   Example, username is foo
  636.  
  637.        kill -9 `ps -aux |grep ^foo |tr -s " " |cut -d " " -f2`
  638.  
  639.   That taken care of, let us move to the forgotten root password.
  640.  
  641.   The solution given in the Gazette is the most universal one, but not
  642.   the easiest one.  With both LILO and loadlin, one may provide the boot
  643.   parameter 'single' to boot directly into the default shell with no
  644.   login or password prompt.  From there, one may change or remove any
  645.   passwords before typing 'init 3' to start multiuser mode.  Number of
  646.   reboots: 1 The other way Number of reboots: 2
  647.  
  648.   Justin Dossey
  649.  
  650.   3.6.  Jim Dennis, jadestar@rahul.net Some tips for new sysadmins.
  651.  
  652.   Create and maintain a /README.`hostname` and/or a
  653.   /etc/README.`hostname` Or possibly /usr/local/etc/README.`hostname`
  654.   -Maint.
  655.  
  656.   Absolutely, from *day one* of administering a system take notes in an
  657.   online log file.  You might make Another way to do this is to write an
  658.   su or a sudo script that does something like:
  659.  
  660.                        function exit \
  661.                                { unset exit; exit; \
  662.                                  cat ~/tmp/session.$(date +%y%m%d) \
  663.                                  >> /README.$(hostname) && \
  664.                                  vi /README.$(hostname)
  665.                                  }
  666.                        script -a ~/tmp/session.$(date +%y%m%d)
  667.                        /bin/su.org -
  668.  
  669.   (use the typescript command to create a session log and create a
  670.   function to automate appending and updating the log).
  671.  
  672.   I'll admit that I haven't implemented this automation of policy --
  673.   I've just relied on self-discipline so far.  However I have been
  674.   toying with the idea (even to the point of prototyping the scripts and
  675.   shell functions as you see them).  One thing that holds me back on
  676.   this is the 'script' command itself.  I think I'll have to grab the
  677.   sources and add a couple of command line parameters (to pause/stop the
  678.   script recording from the command line) before I commit to using
  679.   this).
  680.  
  681.   My last suggestion (for this round):
  682.  
  683.   Root's path should consist of 'PATH= /bin'
  684.  
  685.   That's it.  Nothing else on root's path.  Everything root does is
  686.   provided by a symlink from  /bin or by an alias or shell function, or
  687.   is a script or binary in  /bin, or is typed out with an explicit path.
  688.  
  689.   This makes anyone running as root aware (sometimes painfully so) of
  690.   how he or she is trusting binaries.  The wise admin of a multi-user
  691.   host will periodically look through his or here  /bin and  /.*history
  692.   files to look for patterns and loopholes.
  693.  
  694.   The really motivated admin will spot sequences that can be automated,
  695.   places where sanity checks can be inserted, and tasks for which 'root'
  696.   privileges should be temporarily eschewed (launching editors, MTA's
  697.   and other large interactive programs with elaborate scripting features
  698.   that *might* be embedded in transparent or data files -- like the
  699.   infamous vi ./.exrc and emacs ./.emacs and the even more insidous
  700.   $EXINIT and the embedded header/footer macros).  Naturally those sorts
  701.   of commands can be run with something like:
  702.  
  703.                        cp $data $some_users_home/tmp
  704.                        su -c $origcommand $whatever_switches
  705.                        cp $some_users_home/tmp $data
  706.  
  707.   (...where the specifics depend on the command).
  708.  
  709.   Mostly these last sorts of precautions are overboard for the home or
  710.   'single' user workstation -- but they are very good policy the admin
  711.   of a multi-user -- particular a publicly exposed system (like the
  712.   one's at netcom).
  713.  
  714.   3.7.  How to configure xdm's chooser for host selection. Arrigo Tri¡
  715.   ulzi, a.triulzi@ic.ac.uk
  716.  
  717.   1. Edit the file that launches xdm most likely /etc/rc/rc.6 or
  718.      /etc/rc.local) so that it contains the following lines in the xdm
  719.      startup section.
  720.  
  721.        /usr/bin/X11/xdm
  722.        exec /usr/bin/X11/X -indirect hostname
  723.  
  724.   2. Edit /usr/lib/X11/xdm/Xservers and comment out the line which
  725.      starts the server on the local machine (i.e. starting 0:)
  726.   3. Reboot the machine and you're home and away.
  727.  
  728.   I add this because when I was, desperately, trying to set it up for my
  729.   own subnet over here it took me about a week to suss out all the
  730.   problems.
  731.  
  732.   Caveat: with old SLS (1.1.1) for some reason you can leave a -nodaemon
  733.   after the xdm line -- this does NOT work for later releases.
  734.  
  735.